class Solution:
    def maxProfit(self, prices) -> int:
        if len(prices) <= 1:
            return 0
        dp_max = 0
        min_price = prices[0]

        for i in range(1, len(prices)):
            # 包含的
            dp_had = prices[i] - min_price
            dp_max = max(dp_had, dp_max)
            if prices[i] < min_price:
                min_price = prices[i]

        return max(0, dp_max)


if __name__ == '__main__':
    so = Solution()
    t = [7,6,4,3,1]
    r = so.maxProfit(t)
    print(r)
